home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7222 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: nntp.earthlink.net!usenet
  2. From: laserlight@earthlink.net (Lewis Burmeister)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: A simple "find the bug" (please! I need help :)
  5. Date: Thu, 22 Feb 1996 03:01:55 GMT
  6. Organization: Earthlink Network, Inc.
  7. Message-ID: <4ggmca$fa8@bolivia.it.earthlink.net>
  8. References: <4gdr6n$6p0@guava.epix.net>
  9. NNTP-Posting-Host: laserlight.earthlink.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. jgvd@epix.net (Jon) wrote:
  13.  
  14. >I wrote this just now and it's telling me that when i try to cout the 
  15. >result at the bottom, it is an undefined value even though I did return 
  16. >the result var...  See if you can help.
  17.  
  18. >#include <iostream.h>
  19.  
  20. >float num1;
  21. >float num2;
  22.  
  23. >getnums () {
  24.  
  25. >float result = num1 +num2;
  26.  
  27. >cout << "What number?\n";
  28. >cin >> num1;
  29. >cout << "And?\n";
  30. >cin >> num2;
  31.  
  32. >return result;
  33. >}
  34.  
  35. >main (){
  36.  
  37. >getnums ();
  38.  
  39.  
  40. >cout << result;
  41. >}
  42.  
  43. >        ^^^^^^ right there is the result i want printed but it does not 
  44. >recognize it even though I did try to return the value in the function 
  45. >getnums... am I missing something?
  46.  
  47. >Jon
  48.  
  49. Assuming this is not for a school class , move 
  50. float result = num1 +num2;
  51. down past where you get num1 and num2 values from cin
  52.  
  53.  
  54. cout << "What number?\n";
  55. cin >> num1;
  56. cout << "And?\n";
  57. cin >> num2;
  58. float result = num1 +num2;
  59. return result;
  60.  
  61. Lewis
  62.  
  63.